package com.example.final_project.Home.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.final_project.R;
import com.example.final_project.Usr.entry.GuildSrc;

import java.util.List;

public class GuildAdapter extends RecyclerView.Adapter {

    private Context context;
    private List<GuildSrc> guilds;

    public GuildAdapter(Context context, List<GuildSrc> guilds){
        this.context = context;
        this.guilds = guilds;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.guild_kid,null);
        GHolder gHolder = new GHolder(view);
        return gHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        GHolder gHolder = (GHolder) holder;
        gHolder.setData(position);
    }

    @Override
    public int getItemCount() {
        return guilds.size();
    }

    class GHolder extends RecyclerView.ViewHolder {
        public GHolder(@NonNull View itemView) {
            super(itemView);
        }

        public void setData(int position){
            GuildSrc guildSrc = guilds.get(position);

            ImageView Gsrc = itemView.findViewById(R.id.guild_IV);
            Gsrc.setImageResource(guildSrc.getSrc());
            TextView Gname = itemView.findViewById(R.id.guild_TV);
            Gname.setText(guildSrc.getName());
        }

    }

}
